package com.todo.reward.infrastructure.repository.impl;

import com.todo.common.utils.StringUtils;
import com.todo.reward.common.enums.CouponWOWriteOffEnum;
import com.todo.reward.infrastructure.entity.po.RewardCouponWORecordPO;
import com.todo.reward.infrastructure.mapper.RewardCouponWORecordMapper;
import com.todo.reward.infrastructure.repository.RewardCouponWORecordRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2025/2/12 22:20
 * @description
 */
@Slf4j
@Repository
public class RewardCouponWORecordRepositoryImpl implements RewardCouponWORecordRepository {

    @Resource
    private RewardCouponWORecordMapper rewardCouponWORecordMapper;

    @Override
    public Boolean insertRewardCouponWORecordPO(RewardCouponWORecordPO rewardCouponWORecordPO) {
        if (rewardCouponWORecordPO == null) {
            return false;
        }
        if (rewardCouponWORecordPO.getCouponTemplateBatch() == null || rewardCouponWORecordPO.getDispatchRecordId() == null
                || rewardCouponWORecordPO.getUserId() == null || rewardCouponWORecordPO.getWriteOffUk() == null) {
            return false;
        }
        return rewardCouponWORecordMapper.insertRewardCouponWORecordPO(rewardCouponWORecordPO);
    }

    @Override
    public Boolean updateRewardCouponWORecordPO(RewardCouponWORecordPO rewardCouponWORecordPO) {
        if (rewardCouponWORecordPO == null || rewardCouponWORecordPO.getId() == null) {
            return false;
        }
        return rewardCouponWORecordMapper.updateRewardCouponWORecordPO(rewardCouponWORecordPO);
    }

    @Override
    public Boolean removeRewardCouponWORecordPOById(Long id) {
        if (id == null || id < 0) {
            return false;
        }
        return rewardCouponWORecordMapper.removeRewardCouponWORecordPOById(id);
    }

    @Override
    public RewardCouponWORecordPO queryRewardCouponWORecordPOById(Long id) {
        if (id == null || id < 0) {
            return null;
        }
        return rewardCouponWORecordMapper.queryRewardCouponWORecordPOById(id);
    }

    @Override
    public RewardCouponWORecordPO queryRewardCouponWORecordPOByDispatchRecordId(Long dispatchRecordId) {
        if (dispatchRecordId == null || dispatchRecordId < 0) {
            return null;
        }
        return rewardCouponWORecordMapper.queryRewardCouponWORecordPOByDispatchRecordId(dispatchRecordId);
    }

    @Override
    public RewardCouponWORecordPO queryRewardCouponWORecordPOByWriteOffUk(String writeOffUk) {
        if (StringUtils.isBlank(writeOffUk)) {
            return null;
        }
        return rewardCouponWORecordMapper.queryRewardCouponWORecordPOByWriteOffUk(writeOffUk);
    }

    @Override
    public Boolean updateRecordWriteOffTypeById(Long id, CouponWOWriteOffEnum oldWriteOffType, CouponWOWriteOffEnum newWriteOffType) {
        if (id == null || id < 0 || oldWriteOffType == null || newWriteOffType == null) {
            return false;
        }
        return rewardCouponWORecordMapper.updateRecordWriteOffTypeById(id, oldWriteOffType.getType(), newWriteOffType.getType());
    }
}
